package uplb.ics.cs190.e2d.object;

public class Timer {

	protected boolean active;
	protected long delay;
	protected long currentTick;
	
	public Timer(long delay) {
		this.active = true;
		this.delay = delay;
	}
	
	public boolean action(long elapsedTime) {
		if(this.active) {
			this.currentTick += elapsedTime;
			if(this.currentTick >= this.delay) {
				this.currentTick -= this.delay;
				return true;
			}
		}
		return false;
	}
	
	public void refresh() {
		this.currentTick = 0;
	}
	
	public void synchWith(Timer other) {
		this.active = other.active;
		this.delay = other.delay;
		this.currentTick = other.currentTick;
	}
	
	public boolean isActive() {
		return this.active;
	}
	
	public void setActive(boolean flag) {
		this.active = flag;
	}
	
	public long getDelay() {
		return this.delay;
	}
	
	public void setDelay(long delay) {
		this.delay = delay;
	}
	
	public long getCurrentTick() {
		return this.currentTick;
	}
	
	public void setCurrentTick(long tick) {
		this.currentTick = tick;
	}
}
